
#include <bur/plctypes.h>

#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif

#include <string.h>
#include <math.h>


float GetMean(void* base, int size, int count)
{
	int i = 0;
	char* p = base;
	float sum = 0;
	for (i = 0; i < count; i++)
	{
		sum += (float)p[i*size];
	}
	return sum / count;
}

float GetVariance(void* base, int size, int count, float mean)
{
	int i = 0;
	int* p = base;
	if (mean == 0)
		mean = GetMean(base, size, count);
	
	float sum = 0;
	for (i = 0; i < count; i++)
	{
		sum += pow((float)p[i*size] - mean, 2);
	}
	return sum / count;
}

float GetStdDeviation(void* base, int size, int count, float mean)
{
	return pow(GetVariance(base, size, count, mean), 0.5);
}
